Skip to content

Conversation

@fepegar
Copy link
Member

@fepegar fepegar commented Feb 4, 2026

import torchio as tio
import yaml

spacing = 2
size = 192
ct_window = -1000, 1000
model_range = -1, 1
orientation = 'SAR'

transforms = [
    tio.ToOrientation(orientation),
    tio.Resample(spacing),
    tio.RescaleIntensity(out_min_max=model_range, in_min_max=ct_window),
    tio.Clamp(*model_range),
    tio.CropOrPad(size, padding_mode='minimum'),
]
composed_transform = tio.Compose(transforms)
cfg = composed_transform.to_hydra_config()
yaml_str = yaml.dump(cfg)
print(yaml_str)
_target_: torchio.transforms.augmentation.composition.Compose                                                      
copy: true                                                                                                         
exclude: null                                                                                                      
include: null                                                                                                      
transforms:                                                                                                        
- _target_: torchio.transforms.preprocessing.spatial.to_orientation.ToOrientation                                  
  copy: true                                                                                                       
  exclude: null                                                                                                    
  include: null                                                                                                    
  orientation: SAR                                                                                                 
- _target_: torchio.transforms.preprocessing.spatial.resample.Resample                                             
  antialias: false                                                                                                 
  copy: true                                                                                                       
  exclude: null                                                                                                    
  image_interpolation: linear                                                                                      
  include: null                                                                                                    
  label_interpolation: nearest                                                                                     
  pre_affine_name: null                                                                                            
  scalars_only: false                                                                                              
  target: 2                                                                                                        
- _target_: torchio.transforms.preprocessing.intensity.rescale.RescaleIntensity                                    
  copy: true                                                                                                       
  exclude: null                                                                                                    
  in_min_max:                                                                                                      
  - -1000                                                                                                          
  - 1000                                                                                                           
  include: null                                                                                                    
  masking_method: null                                                                                             
  out_min_max:                                                                                                     
  - -1                                                                                                             
  - 1                                                                                                              
  percentiles:                                                                                                     
  - 0                                                                                                              
  - 100                                                                                                            
- _target_: torchio.transforms.preprocessing.intensity.clamp.Clamp                                                 
  copy: true                                                                                                       
  exclude: null                                                                                                    
  include: null                                                                                                    
  out_max: 1                                                                                                       
  out_min: -1                                                                                                      
- _target_: torchio.transforms.preprocessing.spatial.crop_or_pad.CropOrPad                                         
  copy: true                                                                                                       
  exclude: null                                                                                                    
  include: null                                                                                                    
  labels: null                                                                                                     
  mask_name: null                                                                                                  
  only_crop: false                                                                                                 
  only_pad: false                                                                                                  
  padding_mode: minimum                                                                                            
  target_shape:                                                                                                    
  - 192                                                                                                            
  - 192                                                                                                            
  - 192  

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds support for exporting TorchIO transforms into Hydra-compatible config dictionaries (via a new to_hydra_config() API), and introduces a new runtime warning when plotting multi-channel images without specifying a channel.

Changes:

  • Add Transform.to_hydra_config() plus helpers to build Hydra instantiation dictionaries.
  • Add Compose.to_hydra_config() to recursively export nested transform pipelines.
  • Warn in plot_volume() when a multi-channel image is plotted without specifying channel (defaults to channel 0).

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 4 comments.

File Description
src/torchio/visualization.py Adds a warning when defaulting to the first channel for multi-channel images.
src/torchio/transforms/transform.py Introduces Hydra export helpers and to_hydra_config() on the base Transform.
src/torchio/transforms/augmentation/composition.py Adds Hydra export for Compose and typing aliases for config dicts.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@fepegar fepegar merged commit 9d8a98a into main Feb 10, 2026
33 checks passed
@fepegar fepegar deleted the add-export-hydra-config branch February 10, 2026 10:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant